package com.sum.tea.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.sum.tea.databinding.ListitemviewRegBinding

class RegListAdapter(
    private val context: Context,
    private val dataList: List<Map<String, String>>
) : RecyclerView.Adapter<RegListAdapter.RegViewHolder>() {

    inner class RegViewHolder(val binding: ListitemviewRegBinding) :
        RecyclerView.ViewHolder(binding.root)

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RegViewHolder {
        val binding = ListitemviewRegBinding.inflate(
            LayoutInflater.from(context),
            parent,
            false
        )
        return RegViewHolder(binding)
    }

    override fun onBindViewHolder(holder: RegViewHolder, position: Int) {
        val item = dataList[position]
        holder.binding.textViewRegnumber.text = item["number"]
        holder.binding.textViewRegaddress.text = item["address"]
        holder.binding.textViewRegval.text = item["value"]
    }

    override fun getItemCount(): Int = dataList.size
}